# -*- coding: UTF-8 -*-
from . import app
from flask import request
from module_server import *

# 添加服务器列表
@app.route('/interface/server/add', methods=['GET', 'POST'])
def interface_server_add():
    if request.method == 'POST':
        server_ip = request.form['server_ip']
        server_group = request.form['server_group']
        server_obj = Server(server_ip = server_ip, server_group = server_group)
        server_add(server_obj)
        return server_query_all()

# 更新server列表
@app.route('/interface/server/update', methods=['GET', 'POST'])
def interface_server_update():
    if request.method == 'POST':
        id = request.form['id']
        server_ip = request.form['server_ip']
        server_group = request.form['server_group']
        server_update(id, server_ip, server_group)
        return '更新成功！'

# 删除server列表
@app.route('/interface/server/delete', methods=['GET', 'POST'])
def interface_server_delete():
    if request.method == 'POST':
        id = request.form['id']
        server_delete_from_id(id)
        return server_query_all()

# 查询服务器列表all
@app.route('/interface/server/select_all')
def interface_server_select_all():
    return server_query_all()

# 查询软件列表id和softname
@app.route('/interface/server/select_id_server_group')
def interface_server_select_id_server_group():
    result = []
    server_objs = server_query_id_server_group()
    return json.dumps(server_objs)